package com.bestcem.xm.user.grpc.client;

import com.bestcem.xm.common.core.constant.GrpcClientNames;
import com.bestcem.xm.messagecenter.grpc.v1.services.InitDefaultTemplateRequest;
import com.bestcem.xm.messagecenter.grpc.v1.services.InitDefaultTemplateResponse;
import com.bestcem.xm.messagecenter.grpc.v1.services.MessagecenterServiceGrpc;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;
import zhongyan.xm.base.v1.Base;

import java.util.Objects;

@Slf4j
@Service(value = "messageCenterService")
public class MessageCenterService {

    @GrpcClient(GrpcClientNames.DS_QDES)
    private MessagecenterServiceGrpc.MessagecenterServiceBlockingStub messagecenterServiceBlockingStub;

    //初始化插入默认模板
    public void initDefaultTemplate(String orgId) {
        InitDefaultTemplateRequest.Builder builder = InitDefaultTemplateRequest.newBuilder();
        builder.setOrgId(orgId);
        try {
            InitDefaultTemplateResponse response = messagecenterServiceBlockingStub.initDefaultTemplate(builder.buildPartial());
            if (Objects.isNull(response) || Base.Code.ERROR.equals(response.getStatus().getCode())) {
                log.error("[user] MessageCenter initDefaultTemplate orgId={} Error; ErrorMsg: {}", orgId, response);
            }
        } catch (Exception e) {
            log.error("[user] MessageCenter initDefaultTemplate orgId={};Error;", orgId);
        }
    }
}
